home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 2 / CU Amiga Magazine's Super CD-ROM 02 (1996)(EMAP Images)(GB)[!][issue 1996-04].iso / magazine / amiga_e / address.e < prev    next >
Text File  |  1995-02-11  |  2KB  |  113 lines

  1. OPT MODULE
  2. -> address.e by Trey Van Riper of the Cheese Olfactory Workshop
  3.  
  4. MODULE '*string','*sortobj'
  5.  
  6. -> address.e is a derived object from 'sortobj', but we'll sort to lname.
  7.  
  8. EXPORT OBJECT address OF sortobj
  9.  lname:PTR TO string
  10.  fname:PTR TO string
  11.  street:PTR TO string
  12.  city:PTR TO string
  13.  phone:PTR TO string
  14. ENDOBJECT 
  15.  
  16. -> We have much to initialize here.
  17.  
  18. PROC init() OF address
  19.  DEF tmp:PTR TO string
  20.  NEW tmp.new()
  21.  self.fname:=tmp
  22.  NEW tmp.new()
  23.  self.lname:=tmp
  24.  NEW tmp.new()
  25.  self.street:=tmp
  26.  NEW tmp.new()
  27.  self.city:=tmp
  28.  NEW tmp.new()
  29.  self.phone:=tmp
  30. ENDPROC
  31.  
  32. -> Sets the first name.
  33.  
  34. EXPORT PROC setFname(in) OF address
  35.  self.fname.set(in)
  36. ENDPROC
  37.  
  38. -> These two functions set the last name.
  39.  
  40. EXPORT PROC set(in) OF address
  41.  self.setLname(in)
  42. ENDPROC
  43.  
  44. EXPORT PROC setLname(in) OF address
  45.  self.lname.set(in)
  46. ENDPROC
  47.  
  48. -> Sets the Street address.
  49.  
  50. EXPORT PROC setStreet(in) OF address
  51.  self.street.set(in)
  52. ENDPROC
  53.  
  54. -> Sets the City/State
  55.  
  56. EXPORT PROC setCity(in) OF address
  57.  self.city.set(in)
  58. ENDPROC
  59.  
  60. -> Sets the phone #.
  61.  
  62. EXPORT PROC setPhone(in) OF address
  63.  self.phone.set(in)
  64. ENDPROC
  65.  
  66. -> Most addresses are sorted to the last name (at least
  67. -> where I'm from), so the sorting is doing according to the
  68. -> last name.
  69.  
  70. EXPORT PROC cmp(item:PTR TO address) OF address
  71.  RETURN self.lname.cmp(item.lname)
  72. ENDPROC
  73.  
  74. -> This helps determine how much 'write' will require.
  75.  
  76. EXPORT PROC size() OF address
  77.  DEF out
  78.  out := self.lname.size() + self.street.size() + self.city.size() + self.phone.size() + self.fname.size() + 40
  79. ENDPROC out
  80.  
  81. -> write() comes up with a text suitable to printing out an
  82. -> address.  Could be neater, but hey, it's only an example.
  83.  
  84. EXPORT PROC write() OF address
  85.  DEF out
  86.  out:=String(self.size())
  87.  StringF(out,'Name: "\s, \s"\nStreet: \s\nCity: \s\nPhone: \s\n',self.lname.write(),
  88.                                   self.fname.write(),
  89.                                   self.street.write(),
  90.                                  self.city.write(),
  91.                                  self.phone.write())
  92. ENDPROC out
  93.  
  94. -> This is a unique id # for address: "addr"
  95.  
  96. EXPORT PROC id() OF address IS "addr"
  97.  
  98. -> Tons-o-stuff to deallocate.
  99.  
  100. EXPORT PROC end() OF address
  101.  DEF tmp:PTR TO string
  102.  tmp:=self.street
  103.  END tmp
  104.  tmp:=self.city
  105.  END tmp
  106.  tmp:=self.phone
  107.  END tmp
  108.  tmp:=self.lname
  109.  END tmp
  110.  tmp:=self.fname
  111.  END tmp
  112. ENDPROC
  113.